/**
 *====================================================
* 文件名称: ClaimCoverageServiceImpl.java
 * 修订记录：
  * No    日期				作者(操作:具体内容)
  * 1.    2015年12月09日	chenxy(创建:创建文件)
  *====================================================
  * 类描述：(说明未实现或其它不应生成javadoc的内容)
  */
package com.yuexunit.finance.project.service;

import java.math.BigDecimal;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.common.util.BeanUtils;
import com.yuexunit.finance.project.entity.ClaimCoverageEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.persist.PersistUtil;

/**
 * @ClassName: ClaimCoverageServiceImpl
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author chenxy
 * @date 2015年12月09日 11:07:15
 */
@Implements(ClaimCoverageService.class)
public class ClaimCoverageServiceImpl implements ClaimCoverageService {

	@Override
	public Long createClaimCoverage(ClaimCoverageEntity entity) {
		entity.setIndemnityAmount(BigDecimal.ZERO);
		entity.setIndemnityDate(null);
		PersistUtil.insert(entity);
		return entity.getClaimCoverageId();
	}

	@Override
	public void updateClaimCoverage(ClaimCoverageEntity entity) {
		ClaimCoverageEntity persist = inquireClaimCoverage(entity.getClaimCoverageId());
		BeanUtils.copyProperties(entity, persist, "indemnityDate", "indemnityAmount");
		PersistUtil.update(persist);
	}

	@Override
	public void renovateClaimCoverage(ClaimCoverageEntity persist) {
		PersistUtil.update(persist);
	}

	@Override
	public ClaimCoverageEntity inquireClaimCoverage(Long claimCoverageId) {
		return PersistUtil.get(ClaimCoverageEntity.class, claimCoverageId);
	}

	@Override
	public List<ClaimCoverageEntity> inquireClaimCoverageList(Long claimId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(ClaimCoverageEntity.class);
		criteria.add(Restrictions.ge("claimId", claimId));
		return PersistUtil.get(criteria);
	}

	@Override
	public ClaimCoverageEntity inquireClaimCoverage(Long insuranceCoverageId, Long claimId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(ClaimCoverageEntity.class);
		criteria.add(Restrictions.ge("insuranceCoverageId", insuranceCoverageId));
		criteria.add(Restrictions.ge("claimId", claimId));
		List<ClaimCoverageEntity> list = PersistUtil.get(criteria);
		if (list.isEmpty()) {
			return null;
		}
		return list.get(0);
	}

}
